import httpUtil from "@/utils/httpUtil";
import messageUtil from "../utils/messageUtil";
import userApi from "./userApi";


/**
 * 微信小程序专用，用于获取手机号
 */
const getWxMiniMobile = (code, successCallBack, failCallBack) => {
	let params = {
		code,
		openid: userApi.getUserId(),
	}
	httpUtil.post('/api/ng/getPhone', params, res => {

		// {
		// 	"code": 1,
		// 	"msg": "ok",
		// 	"time": "1690792891",
		// 	"data": {
		// 		"phoneNumber": "13880104834",
		// 		"purePhoneNumber": "13880104834",
		// 		"countryCode": "86",
		// 		"watermark": {
		// 			"timestamp": 1690792868,
		// 			"appid": "wx8b15dc2c1ee47c1f"
		// 		}
		// 	}
		// }
		if (successCallBack) {
			successCallBack(res.data.phoneNumber)
		}
	}, err => {
		if (failCallBack) {
			failCallBack(err)
		}
	})
}

/**
 * 通过手机号获取运营商相关信息
 * @param phone
 * @param backMethod
 * @return {JSON} {"Mobile": "13880104834","Province": "四川","City": "成都","Isp": "中国移动"}
 */
const getOperator = (mobile, backMethod) => {


	httpUtil.postReturnSource('/api/jssxk/getYys', {
		mobile
	}, res => {
		// {"code": 0,"reason": "Succ","result": {"Mobile": "13880104834","Province": "四川","City": "成都","Isp": "中国移动"}}
		console.log('getOperator', res)
		if (res.reason != 'Succ' || res.code != 0) {
			messageUtil.showFail('获取运营商失败，请于管理员联系')
			return;
		}
		backMethod(res.result);
	})


}

export default {
	getOperator,
	getWxMiniMobile,
}